package com.wngbms.feigndemo.controller;

import com.wngbms.feigndemo.api.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;

@Slf4j
@RestController
public class UserResource implements UserService {

    @Autowired
    HttpServletRequest request;

    @Override
    public String notifyUser(String userId, String eventID) {
        Enumeration<String> headerNames = request.getHeaderNames();
        while (headerNames.hasMoreElements()) {
            String s = headerNames.nextElement();
            String header = request.getHeader(s);
            log.info("header {}:{}", s, header);
        }
        Enumeration<String> parameterNames = request.getParameterNames();
        while (parameterNames.hasMoreElements()) {
            String s = parameterNames.nextElement();
            String parameter = request.getParameter(s);
            log.info("param {}:{}", s, parameter);
        }

        log.info("userId:{}, eventId:{}", userId, eventID);
        return "success";
    }

    @Override
    public String forceCloseUser(String userId) {
        log.info("userId:{}", userId);
        return "success";
    }
}
